package by.home.actions;


import by.home.*;
import by.home.controller.Params;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;


public class ShowChatRooms extends ChatAction {

  @Override
  public Params executeAndGet(Map params) throws IOException, ClassNotFoundException {

    String responsePage;
    ChatServiceInterface chatService = this.getChatService();
    ResponseURIGenerator uriGenerator = this.getUriGenerator();
    ArrayList<ChatRoom> chatRooms = chatService.getAllChatRooms();

    Parameters parameters = new Parameters();


    if (chatRooms != null) {
      parameters.setChatRooms(chatRooms);
      responsePage = uriGenerator.generateResponsePageAfterSuccessfullGettingAllChatRooms();
      parameters.setResponsePage(responsePage);
    } else {
      responsePage = uriGenerator.generateResponsePageAfterFailedGettingAllChatRooms();
      parameters.setResponsePage(responsePage);
    }

    return parameters;
  }
}
